#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "print_html.h"

void printHTTPResponseHeader()
{
    printf("Content-type: text/html;charset=utf-8\n\n");
}

void printHTMLStyles()
{
    printf( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/style_form.css\" />\n" );
}

void printHTMLHead(void)
{
    printf( "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n\"http://www.w3.org/TR/html4/loose.dtd\">\n" );
    printf( "<html>\n" );
    printf( "<head>\n" );
    printf( "<title>Form</title>\n" );
    printHTMLStyles();
    printf( "</head>\n" );
    printf( "<body>\n" );
}

void printHTMLEnd(void)
{
    printf( "</body>\n" );
    printf( "</html>\n" );
}

void printHTMLHeaderLine(void)
{
    printf("<form action=\"read_from_form.cgi\" method=\"POST\" name=\"form\" enctype=\"text/plain\">\n");
    printf("<div class=\"title\">\n");
    printf("<p class=\"header\">Sign Up</p>\n");
    printf("<p class=\"underhead\">It's free and always will be.</p>\n");
    printf("</div>\n");

    printf("<hr class=\"separator\" size=\"1\" />\n");
}

void printHTMLInputData(void)
{
    printf("<div class=\"question\">\n");
    printf("<label for=\"lastName\">Last Name:</label>\n");
    printf("<input class=\"input\" type=\"text\" name=\"lastName\" id=\"lastName\" size=\"30\">\n");
    printf("</div>\n");

    printf("<div class=\"question\">\n");
    printf("<label for=\"email\">Your Email:</label>\n");
    printf("<input class=\"input\" type=\"text\" name=\"email\" id=\"email\" size=\"30\">\n");
    printf("</div>\n");

    printf("<div class=\"question\">\n");
    printf("<label for=\"reEmail\">Re-enter Email:</label>\n");
    printf("<input class=\"input\" type=\"text\" name=\"reEmail\" id=\"reEmail\" size=\"30\">\n");
    printf("</div>\n");

    printf("<div class=\"question\">\n");
    printf("<label for=\"password\">New Password:</label>\n");
    printf("<input class=\"input\" type=\"password\" name=\"password\" id=\"password\" size=\"30\" maxlength=\"10\">\n");
    printf("</div>\n");
}

void printHTMLSexSelector(void)
{
    printf("<div class=\"question sex\" id=\"sex\">\n");
    printf("<label for=\"select_sex\">I am:</label>\n");
    printf("<select name=\"sex\" id=\"select_sex\">\n");
    printf("<option selected=\"selected\">Select Sex:</option>\n");
    printf("<option>Male</option>\n");
    printf("<option>Female</option>\n");
    printf("</select>\n");
    printf("</div>\n");
}

void printMonths(void)
{
    char *months[] = {"January","February", "Marth", "April", "May", "June", "July", "August",
                     "September", "October", "November", "December"};
    unsigned i=0;
    while(i < 12)
    {
        printf("<option>%s</option>\n", months[i]);
        ++i;
    }
}

void printDays(void)
{
    unsigned i=1;
    while(i < 32)
    {
        printf("<option>%d</option>\n", i);
        ++i;
    }
}

void printYears(void)
{
    unsigned i=1900;
    while(i < 2012)
    {
        printf("<option>%d</option>\n", i);
        ++i;
    }
}

void printHTMLBirthDaySelector(void)
{
    printf("<div class=\"question birthday\" id=\"birthday\">\n");
    printf("<label for=\"month\">Birthday:</label>\n");
    printf("<select name=\"month\" id=\"month\" class=\"month\">\n");
    printf("<option selected>Month:</option>\n");
    printMonths();
    printf("</select>\n");

    printf("<select name=\"day\" id=\"day\" class=\"day\">\n");
    printf("<option selected>Day:</option>\n");
    printDays();
    printf("</select>\n");

    printf("<select name=\"year\" id=\"year\" class=\"year\">\n");
    printf("<option selected>Year:</option>\n");
    printYears();
    printf("</select>\n");
    printf("</div>\n");
}

void printHTMLFooter(void)
{
    printf("<div class=\"footer\">\n");
    printf("<a href=\"http://google.com\">\n");
    printf("<p>Why do I need to provide this?</p>\n");
    printf("</a>\n");
    printf("</div>\n");

    printf("<div class=\"button\">\n");
    printf("<input type=\"image\" src=\"../images/sign.png\" name=\"signUp\">\n");
    printf("</div>\n");

    printf("</form>\n");
}